/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024.
 * Description: a high performance way to acquire cpu and memory stat, declare
 * the information we need here
 * Author: Pang LiYuan
 * Create: 2024-04-08
 */
#include <linux/kbuild.h>
#include <linux/vmstat.h>
#include <linux/rtos_hpstat.h>

struct rtos_hpstat_shared_mirror {
#ifdef CONFIG_RTOS_HP_OBTAIN_STAT_MEM
	_Atomic(long) vm_zone_stat[NR_VM_ZONE_STAT_ITEMS] __aligned(SMP_CACHE_BYTES);
	_Atomic(long) vm_numa_stat[NR_VM_NUMA_STAT_ITEMS] __aligned(SMP_CACHE_BYTES);
	_Atomic(long) vm_node_stat[NR_VM_NODE_STAT_ITEMS] __aligned(SMP_CACHE_BYTES);
	_Atomic(unsigned long) rtos_totalreserve_pages;
#endif
#ifdef CONFIG_RTOS_HP_OBTAIN_STAT_CPU
	_Atomic(u64) cpu_idle_timeset[RTOS_CPU_USAGE_MAX_CPU];
#endif
};

#ifdef CONFIG_RTOS_HP_OBTAIN_STAT_MEM
#define member_size(type, member) (sizeof(((type *)NULL)->member))
static_assert(sizeof(vm_zone_stat) == member_size(struct rtos_hpstat_shared_mirror, vm_zone_stat),
	"vm_zone_stat size error!");
static_assert(sizeof(vm_numa_stat) == member_size(struct rtos_hpstat_shared_mirror, vm_numa_stat),
	"vm_numa_stat size error!");
static_assert(sizeof(vm_node_stat) == member_size(struct rtos_hpstat_shared_mirror, vm_node_stat),
	"vm_node_stat size error!");
#endif

int main(void)
{
#ifdef CONFIG_RTOS_HP_OBTAIN_STAT_MEM
	DEFINE(ITEMS_NR_VM_ZONE_STAT,	NR_VM_ZONE_STAT_ITEMS);
	DEFINE(ITEMS_NR_VM_NUMA_STAT,	NR_VM_NUMA_STAT_ITEMS);
	DEFINE(ITEMS_NR_VM_NODE_STAT,	NR_VM_NODE_STAT_ITEMS);
	DEFINE(ASM_SMP_CACHE_BYTES,		SMP_CACHE_BYTES);
	DEFINE(OFFSET_NR_VM_ZONE_STAT,	offsetof(struct rtos_hpstat_shared_mirror, vm_zone_stat));
	DEFINE(OFFSET_NR_VM_NUMA_STAT,	offsetof(struct rtos_hpstat_shared_mirror, vm_numa_stat));
	DEFINE(OFFSET_NR_VM_NODE_STAT,	offsetof(struct rtos_hpstat_shared_mirror, vm_node_stat));
	DEFINE(OFFSET_RTOS_TOTALRESERVE_PAGES,
		offsetof(struct rtos_hpstat_shared_mirror, rtos_totalreserve_pages));
	DEFINE(RTOS_HP_OBTAIN_STAT_MEM_IS_ENABLED, 1);
#else
	DEFINE(RTOS_HP_OBTAIN_STAT_MEM_IS_ENABLED, 0);
#endif

#ifdef CONFIG_RTOS_HP_OBTAIN_STAT_CPU
	DEFINE(ITEMS_CPU_IDLE_TIMESET,	RTOS_CPU_USAGE_MAX_CPU);
	DEFINE(OFFSET_CPU_IDLE_TIMESET,	offsetof(struct rtos_hpstat_shared_mirror, cpu_idle_timeset));
	DEFINE(RTOS_HP_OBTAIN_STAT_CPU_IS_ENABLED, 1);
#else
	DEFINE(RTOS_HP_OBTAIN_STAT_CPU_IS_ENABLED, 0);
#endif

	BLANK();
	return 0;
}
